#include "Soldier.h"

int Soldier::init()
{
	return Database::addSoldier(roll(6,5));
}

void Soldier::attackTarget(int soldier)
{
	int target = Database::s_getTarget(soldier);
	if(target == -1)
		target = Database::s_newTarget(soldier);
	if(!takeDamage(target,roll(6,1)))
		Database::s_setTarget(soldier,-1);
}

void Soldier::rest(int soldier)
{
	int health = Database::s_getHealth(soldier);
	int max = Database::s_getAttribute(soldier, "MAXHEALTH");
	health++;	// just increase by one for now; later by con modifier
	if(health > max) health = max;
	Database::s_setHealth(soldier,health);
}

void Soldier::retreat(int soldier)
{
}

bool Soldier::takeDamage(int soldier, int damage)
{
	int health = Database::s_getHealth(soldier);
	health -= damage;
	if(health <= 0)	// just make 0 dead
		health = 0;	// note: later, -1 will be unrevivable
	Database::s_setHealth(soldier, health);
	if(health == 0)
		return false;
	return true;
}